﻿' LibWowArmory
' by Ronald M. Clifford (roncli@roncli.com)
'
' This source code is released under the GNU Library General Public License (LGPL) Version 2.1.

Imports System.IO
Imports System.Linq
Imports System.Xml.Serialization

Namespace roncliProductions.LibWowArmory

    ''' <summary>
    ''' A class to determine if we are logged in to the Armory
    ''' </summary>
    ''' <remarks></remarks>
    Public Class LoginStatus
        Inherits WowArmoryData

        Private lssPage As New LoginStatusSchema.page

        ''' <summary>
        ''' The URL of the login status page
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overrides ReadOnly Property URL() As String
            Get
                Return "http://www.wowarmory.com/login-status.xml"
            End Get
        End Property

        ''' <summary>
        ''' Indicates to the inherited class that this request does not require login
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overrides ReadOnly Property RequiresLogin() As Boolean
            Get
                Return False
            End Get
        End Property

        ''' <summary>
        ''' The username of the person logged into the Armory
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property LoggedInUsername() As String
            Get
                Return lssPage.loginStatus.First().username
            End Get
        End Property

        ''' <summary>
        ''' Constructor that checks to see if someone is logged into the Armory
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
            MyBase.Retrieve()

            Dim xsSerializer As New XmlSerializer(lssPage.GetType())

            Dim srXML As New StringReader(MyBase.strData)

            lssPage = CType(xsSerializer.Deserialize(srXML), LoginStatusSchema.page)
        End Sub

    End Class

End Namespace